REM - Khai bao bien ngay va maps o dia mang ve
@echo off
for /f "tokens=1,2,3 delims=/ " %%a in ('DATE /T') do set date=%%c-%%b-%%a
net use V: \\192.168.1.246\C$ /user:localhost\administrator abc*123

REM - Bat dau dinh nghia bien va backup Database
REM ==========================================

set Backup_Path=V:\Backup_Redmine\
set mysqldump_exe_file="C:\Projects\Redmine\mysql\bin\mysqldump.exe"
%mysqldump_exe_file% -u bitnami --password=dbccfaffe6 bitnami_redmine > %Backup_Path%database_%date%.sql


REM ==========================================
REM - Ket thuc viec backup Database


REM - Bat dau viec backup Attach file trong Redmine
REM ==========================================

set Backup_Attach_File_Path=V:\Backup_Redmine\Attach_File_%date%
set Redmine_Attached_Path="C:\Projects\Redmine\apps\redmine\files"
set winrar_exe_file="C:\Program Files\WinRAR\rar.exe"
%winrar_exe_file% a %Backup_Attach_File_Path% -rr524288 -r %Redmine_Attached_Path%

REM ==========================================
REM - Ket thuc viec backup Attach file trong Redmine


REM - Bat dau viec xoa file backup cu hon 7 ngay ( neu ton tai file backup cua ngay hom nay )
REM ==========================================

set max_old_day=3
if exist %Backup_Attach_File_Path%.rar (
    echo "Exists file : %Backup_Attach_File_Path%.rar"
    forfiles -p %Backup_Path% -m *.* -d -%max_old_day%  -c "cmd /c del /q @path"
) else (
    echo "file doesn't exist, nothings to do !"
)

REM ==========================================
REM - Ket thuc viec xoa file backup cu hon 7 ngay
